/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.auction.service.mapper;

import co.yixiang.common.mapper.CoreMapper;
import co.yixiang.modules.auction.domain.YxAuctionLevel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author ycl
* @date 2021-02-19
*/
@Repository
public interface YxAuctionLevelMapper extends CoreMapper<YxAuctionLevel> {

    @Select("<script> SELECT COUNT(DISTINCT(user_id)) from yx_auction_order where DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(now(),'%Y-%m-%d') " +
            " and user_id in (SELECT uid from yx_distributor_relation where p_uid = #{uid}) </script>")
    Integer getDirectDriveNumByUId(@Param("uid") Long uid);

    @Select("SELECT uid from yx_distributor_relation where p_uid = #{uid}")
    List<Long> getUidByPid(@Param("uid") Long uid);

    @Select("SELECT uid from yx_distributor_relation where p_uid in (${uList})")
    List<Long> getUidByPids(@Param("uList") String uList);

    @Select("<script> SELECT COUNT(DISTINCT(user_id)) from yx_auction_order where DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(now(),'%Y-%m-%d') " +
            " and user_id in ( ${uList} ) </script>")
    Integer getValidNum(@Param("uList") String uList);

    @Select("SELECT count(1) from yx_user where uid in (${uList}) and now_level = #{level}")
    Integer getLowerLevelNum(@Param("uList") String uList,@Param("level") Integer level);

    @Select(" SELECT count(1)  from yx_user where uid in (SELECT uid from yx_distributor_relation where p_uid = #{uid}) and now_level = #{level}")
    Integer getLowerLevelNum1(@Param("uid") Long uid,@Param("level") Integer level);
}
